package com.lineage.server.command.executor;

import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Object;
import com.lineage.server.serverpackets.S_Invis;
import com.lineage.server.serverpackets.S_OtherCharPacks;
import com.lineage.server.serverpackets.S_RemoveObject;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1Invisible implements L1CommandExecutor {
  private static final Log _log = LogFactory.getLog(L1Invisible.class);
  
  public static L1CommandExecutor getInstance() {
    return new L1Invisible();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      if (pc.isGmInvis()) {
        pc.setGmInvis(false);
        pc.sendPackets((ServerBasePacket)new S_Invis(pc.getId(), 0));
        pc.broadcastPacketAll((ServerBasePacket)new S_OtherCharPacks(pc));
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("取消GM隐身!"));
      } else {
        pc.setGmInvis(true);
        pc.sendPackets((ServerBasePacket)new S_Invis(pc.getId(), 1));
        pc.broadcastPacketAll((ServerBasePacket)new S_RemoveObject((L1Object)pc));
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("启用GM隐身!"));
      } 
    } catch (Exception e) {
      _log.error("错误的GM指令格式: " + getClass().getSimpleName() + " 执行的GM:" + pc.getName());
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(261));
    } 
  }
}
